/**
 * Created by gongxun on 16/11/18.
 */


var SceneHlper = function(){
    var that = [];

    that.currentLayerName = "";

    that.intoLoginLayer = function(){
        that.runSceneHall();
        mo.mainLayer.intoLoginLayer();

        that.currentLayerName = "login";
    };

    that.runSceneHall = function () {
        if (mo.mainLayer){
            mo.mainLayer.setVisible(true);
        }else{
            mo.mainLayer = new KwxHallLayer();
            mo.sceneMainLayer.addChild(mo.mainLayer);
        }
        mo.mainLayer.closeLoginLayer();

        if (mo.gameLayer){
            mo.gameLayer.setVisible(false);
            mo.gameLayer.removeAllChildren();
        }
        that.currentLayerName = "hall";

        //清理资源
        if (cc.sys.isNative){
            cc.AnimationCache.destroyInstance();
            cc.spriteFrameCache.removeUnusedSpriteFrames();
            cc.textureCache.removeUnusedTextures();
        }
    };

    that.intoHallLayer = function(){
        that.runSceneHall();
    };

    that.showEndInfoLayer = function(node){
        if (mo.endInfoLayer == null){
            mo.endInfoLayer = new cc.Layer();
            mo.sceneMainLayer.addChild(mo.endInfoLayer, 1);
        }
        that.currentLayerName = "hall";

        mo.endInfoLayer.setVisible(true);
        mo.endInfoLayer.removeAllChildren();
        mo.endInfoLayer.addChild(node);
    };

    that.closeEndInfoLayer = function () {
        if (mo.endInfoLayer != null){
            mo.endInfoLayer.setVisible(false);
        }
    };

    that.runSceneKwx = function(){
        if (mo.gameLayer){
            mo.gameLayer.setVisible(true);
        }else{
            mo.gameLayer = new GameMainLayer();
            mo.sceneMainLayer.addChild(mo.gameLayer);
        }

        mo.gameLayer.removeAllChildren();
        var kwxLayer = new KwxTableLayer();
        mo.gameLayer.addChild(kwxLayer);

        if (mo.mainLayer){
            mo.mainLayer.setVisible(false);
        }
        that.currentLayerName = "kwx";
    };


    that.runSceneNn = function(){
        if (mo.gameLayer){
            mo.gameLayer.setVisible(true);
        }else{
            mo.gameLayer = new GameMainLayer();
            mo.sceneMainLayer.addChild(mo.gameLayer);
        }

        mo.gameLayer.removeAllChildren();
        var nnLayer = new NnTableLayer();
        mo.gameLayer.addChild(nnLayer);

        if (mo.mainLayer){
            mo.mainLayer.setVisible(false);
        }
        that.currentLayerName = "nn";
    };

    that.runSceneGsbdx = function(){
        if (mo.gameLayer){
            mo.gameLayer.setVisible(true);
        }else{
            mo.gameLayer = new GameMainLayer();
            mo.sceneMainLayer.addChild(mo.gameLayer);
        }

        mo.gameLayer.removeAllChildren();
        var gsbdxLayer = new GsbdxTableLayer();
        mo.gameLayer.addChild(gsbdxLayer);

        if (mo.mainLayer){
            mo.mainLayer.setVisible(false);
        }
        that.currentLayerName = "gsbdx";
    };

    that.runScenePsz = function(){
        if (mo.gameLayer){
            mo.gameLayer.setVisible(true);
        }else{
            mo.gameLayer = new GameMainLayer();
            mo.sceneMainLayer.addChild(mo.gameLayer);
        }

        mo.gameLayer.removeAllChildren();
        var pszLayer = new PszTableLayer();
        mo.gameLayer.addChild(pszLayer);

        if (mo.mainLayer){
            mo.mainLayer.setVisible(false);
        }
        that.currentLayerName = "psz";
    };

    that.runSceneWhmj = function(){
        if (mo.gameLayer){
            mo.gameLayer.setVisible(true);
        }else{
            mo.gameLayer = new GameMainLayer();
            mo.sceneMainLayer.addChild(mo.gameLayer);
        }

        mo.gameLayer.removeAllChildren();
        var whmjLayer = new WhmjTableLayer();
        mo.gameLayer.addChild(whmjLayer);

        if (mo.mainLayer){
            mo.mainLayer.setVisible(false);
        }
        that.currentLayerName = "whmj";
    };

    that.runSceneDzpk = function(){
        if (mo.gameLayer){
            mo.gameLayer.setVisible(true);
        }else{
            mo.gameLayer = new GameMainLayer();
            mo.sceneMainLayer.addChild(mo.gameLayer);
        }

        mo.gameLayer.removeAllChildren();
        var dzpkLayer = new DzpkTableLayer();
        mo.gameLayer.addChild(dzpkLayer);

        if (mo.mainLayer){
            mo.mainLayer.setVisible(false);
        }
        that.currentLayerName = "dzpk";
    };

    that.runSceneDtj = function(){
        if (mo.gameLayer){
            mo.gameLayer.setVisible(true);
        }else{
            mo.gameLayer = new GameMainLayer();
            mo.sceneMainLayer.addChild(mo.gameLayer);
        }

        mo.gameLayer.removeAllChildren();
        var dtjLayer = new DtjTableLayer();
        mo.gameLayer.addChild(dtjLayer);

        if (mo.mainLayer){
            mo.mainLayer.setVisible(false);
        }
        that.currentLayerName = "dtj";
    };

    that.runSceneDdz = function(){
        if (mo.gameLayer){
            mo.gameLayer.setVisible(true);
        }else{
            mo.gameLayer = new GameMainLayer();
            mo.sceneMainLayer.addChild(mo.gameLayer);
        }

        mo.gameLayer.removeAllChildren();
        var ddzLayer = new DdzTableLayer();
        mo.gameLayer.addChild(ddzLayer);

        if (mo.mainLayer){
            mo.mainLayer.setVisible(false);
        }
        that.currentLayerName = "ddz";
    };

    that.runScenePdk = function(){
        if (mo.gameLayer){
            mo.gameLayer.setVisible(true);
        }else{
            mo.gameLayer = new GameMainLayer();
            mo.sceneMainLayer.addChild(mo.gameLayer);
        }

        mo.gameLayer.removeAllChildren();
        var ddzLayer = new PdkTableLayer();
        mo.gameLayer.addChild(ddzLayer);

        if (mo.mainLayer){
            mo.mainLayer.setVisible(false);
        }
        that.currentLayerName = "pdk";
    };

    that.loadAll = function(){
        // if (mo.gameHelper.testVersion == 0){
        //     mo.mainLayer = new KwxHallLayer();
        //     mo.sceneMainLayer.addChild(mo.mainLayer);
        // }else if (mo.gameHelper.testVersion == 1){
        //     mo.mainLayer = new TestHallLayer();
        //     mo.sceneMainLayer.addChild(mo.mainLayer);
        // }

        // mo.gameLayer = new GameMainLayer();
        // mo.sceneMainLayer.addChild(mo.gameLayer);
    };

    return that;
};

//主界面
mo.mainLayer = null;

//游戏层
mo.gameLayer = null;

//结算层
mo.endInfoLayer = null;

//主场景
mo.mainScene = null;

mo.sceneHelper = new SceneHlper();